package com.zhousb.deviceManager.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhousb.deviceManager.common.PageRequest;
import com.zhousb.deviceManager.common.R;
import com.zhousb.deviceManager.common.ResponseResult;
import com.zhousb.deviceManager.model.bo.AssetBo;
import com.zhousb.deviceManager.model.bo.AssetOutBo;
import com.zhousb.deviceManager.model.entity.KiAsset;
import com.zhousb.deviceManager.model.so.AssetSo;
import com.zhousb.deviceManager.service.AssetService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author zhousb
 * @date 2024/10/29 14:53
 * @description
 */
@RestController
@RequestMapping("/asset")
public class AssetController {

    @Resource
    private AssetService assetService;

    @PostMapping("/page")
    public ResponseResult page(@RequestBody PageRequest<AssetSo> so) {
        return R.success(assetService.page(new Page<>(so.getCurrent(),so.getSize()),so.getQuery() ));
    }

    @PostMapping("/all")
    public ResponseResult all(@RequestBody AssetSo so) {
        return R.success(assetService.all(so));
    }

    @PostMapping("/add")
    public ResponseResult add(@RequestBody AssetBo bo) {
        return R.success(assetService.add(bo));
    }

    @PostMapping("/importExcel")
    public ResponseResult importExcel(@RequestParam("clientId") String clientId,@RequestParam("file") MultipartFile file) throws IOException {
        System.out.println("clientId is ==> "+clientId);
        return R.success(assetService.importExcel(clientId,file));
    }
}
